package com.zhongwang.business.module.basic.controller;

import com.zhongwang.business.base.BaseController;

import com.zhongwang.business.common.JsonResult;
import com.zhongwang.business.constant.Constant;
import com.zhongwang.business.module.basic.model.DictEnumModel;
import com.zhongwang.business.module.basic.service.DictBasicService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;


@Controller
public class DictController extends BaseController {

    @Autowired
    private DictBasicService dictBasicService;

    /**
     * 首页跳转至审核组织架构页面
     *
     * @param model
     * @return
     */
    @GetMapping("/basic/dict")
    @RequiresPermissions({"basic:dict:view"})
    public String orgPage(Model model) {
        List<String> types = dictBasicService.selectTypes();
        model.addAttribute("types", types);
        return "/basicManage/dict/page";
    }


    /**
     * 获取列表
     *
     * @return
     */
    @ResponseBody
    @PostMapping("/dictList")
    public JsonResult selectAllList(DictEnumModel dictEnum) {
        startPage();
        List<DictEnumModel> list = dictBasicService.findDictByCondition(dictEnum);
        return jsonResult(list);
    }

    /**
     * 新增字典数据
     */
    @ResponseBody
    @PostMapping("/dictSave")
    public JsonResult saveOrg(DictEnumModel dictEnum) {
        return isNotNull(dictBasicService.saveDict(dictEnum));
    }

    /**
     * 修改字典数据
     */
    @ResponseBody
    @PostMapping("/dictUpdate")
    public JsonResult update(DictEnumModel dictEnum) {
        return isNotNull(dictBasicService.updateDict(dictEnum));
    }

    /**
     * 删除字典数据
     */
    @ResponseBody
    @PostMapping("/dictDel")
    public JsonResult del(Integer id) {
        return jsonResult(dictBasicService.delDict(id));
    }






}